package bank;
import java.util.*;

public class Account {
    private String account;
    private String name;
    private String id;
    private Date timestamp;
    private double deposit;

    public Account(String account, String name, String id) {
        this.timestamp = new Date();
        this.deposit = 0.00;
        this.account = account;
        this.name = name;
        this.id = id;
        System.out.println("You have open an account");
        System.out.println("Date: "+this.timestamp.toString());
        System.out.println("Account: "+this.account);
        System.out.println("Name: "+this.name);
        System.out.println("ID: "+ this.id);
        System.out.println("Deposit: "+this.deposit);
    }

    public void topUp() {
        double money;
        System.out.print("money to top up:\n> ");
        Scanner scan = new Scanner(System.in);
        if (scan.hasNextDouble()) {
            money = scan.nextDouble();
            this.deposit += money;
        }
        else {
            System.out.println("[Please input digits, try again]");
            topUp();
        }
    }

    public void withdraw() {
        double money;
        System.out.print("money to withdraw:\n> ");
        Scanner scan = new Scanner(System.in);
        if (scan.hasNextDouble()) {
            money = scan.nextDouble();
            if (this.deposit < money) {
                System.out.println("[Sorry, you have no sufficient funds]");
                withdraw();
            }
            else {
                this.deposit -= money;
            }
        }
        else {
            System.out.println("[Please input digits, try again]");
            withdraw();
        }
    }

    public double checkBalance() {
        System.out.println("Your Balance: "+this.deposit);
        return this.deposit;
    }
}
